<template>
    <div>
        <Form :model="form" label-position="left" :label-width="100">
            <FormItem label="填报部门"  prop="title" >
                <Input v-model="form.bmA" style="width: 25%;" disabled></Input>
            </FormItem>
        </Form>
        <Form :model="formLeft" label-position="left" :label-width="100" :rules="ruleValidate">
            <FormItem label="会议标题"  prop="title" >
                <Input v-model="formLeft.title" style="width: 40%" maxlength="100" :show-word-limit="true"/>
                <div style="font-size: 12px;color:#9ea7b4">前两批试点单位部署会议，其他单位再动员再部署会议工作信息</div>
            </FormItem>
            <FormItem label="会议日期" :required="true">
                <DatePicker type="date" style="width: 200px" v-model="formLeft.meeting_time" />
            </FormItem>
            <FormItem label="会议主持人" prop="moderator">
                <Input v-model="formLeft.moderator" style="width: 16%"/>
            </FormItem>
            <FormItem label="正文" prop="article">
                <wl-vue2-editor uploadType="hadoop"
                                uploadUrl="http://218.60.17.11:33685/api/ac/file/fileCommonService/upLoadFiles"
                                getSignUrl="/api/ac/jwork/getHadoopService/getSign" v-model="formLeft.article"></wl-vue2-editor>
            </FormItem>
            <FormItem label="人员情况" :required="true">
                <Input v-model="formLeft.meeting_num" style="width: 15%" placeholder="参会人数" type="number"></Input>
                <Input v-model="formLeft.cadre_num" style="width: 15%;margin-left: 20px" placeholder="其中市管干部人数" type="number"></Input>
                <Input v-model="formLeft.middle_cadres_num" style="width: 16%;margin-left: 20px" placeholder="中层干部（处级）人数" type="number"></Input>
                <Input v-model="formLeft.other_num" style="width: 15%;margin-left: 20px" placeholder="其他人数" type="number"></Input>
            </FormItem>
            <FormItem label="附件上传" prop="enclosure" >
                <wl-upload-oss-files
                        v-model="formLeft.enclosure"
                        :maxNum="50"
                        uploadType="hadoop"
                        uploadStyle="other"
                        uploadUrl='http://218.60.17.11:33685/api/ac/file/fileCommonService/upLoadFiles'
                        getSignUrl="/api/ac/jwork/getHadoopService/getSign"
                        fileName="origin"
                        :beforeUploadFilter="uploadFilter"
                        :format="['doc','docx','pdf','xls','xlsx']"
                        fileDir="/jov/">
                </wl-upload-oss-files>
                <span style="margin-left: 0px;color:#9ea7b4;font-size: 12px">请上传讲话稿等动员部署电子版材料信息，支持PDF，Word和Excel</span>
            </FormItem>
        </Form>
        <Row type="flex" justify="center" class="code-row-bg">
            <Col :gutter="16" span="2">
                <Button type="primary" @click="insert">保存</Button>
            </Col>
            <Col span="7">
                <Button type="success" @click="ok() " :disabled ="nn">完成，并提报“统一思想认识”信息</Button>
            </Col>
        </Row>
        <Row type="flex" justify="center" class="code-row-bg" style="margin-top: 20px">
            <Col span="10">
                <div style="color:#9ea7b4">
                    点击【完成，并“提报统一思想认识”信息】按钮后，仍可继续完善相关信息
                </div>
            </Col>
        </Row>
    </div>
</template>

<script>
import { insertZlUnity, insertZlStateUnity, getCountStateList, updateUnity, countUnityState } from '@/api/user'
export default {

  data () {
    return {
      select_type: '',
      form: {
        bmA: ''
      },
      companyCode: '',
      tm: '',
      state: '',
      aaa: '0',
      content: '',
      nn: false,
      formLeft: {
        meeting_time: '',
        title: '',
        moderator: '',
        cadre_num: '',
        article: '',
        meeting_num: '',
        middle_cadres_num: '',
        other_num: '',
        enclosure: ''
      },
      ruleValidate: {
        title: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        // bmA: [
        //   { required: true, message: '必填项', trigger: 'blur' }
        // ],
        // meeting_time: [
        //   { required: true, message: '必填项', trigger: 'blur' }
        // ],
        moderator: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        article: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        cadre_num: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        meeting_num: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        middle_cadres_num: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        other_num: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        enclosure: [
          { required: true, message: '必填项', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    async init () {
      countUnityState().then(ret => {
        console.log(ret.data.data, 'ret!!!!!!########')
        if (ret.data.data === 0 || ret.data.data === '') {
          this.select_type = '0'
        } else {
          this.select_type = '1'
        }
      })
      // this.formValidate = this.$route.params.aa || {}
      // this.tm = this.$store.state.user.severUserInfo.data.company_name
      // console.log(tm)
    },
    uploadFilter (file, uploadList, filterReturn) {
      console.log(this.url, 'uploadList')
      let isExit = false
      if (uploadList.length > 0) {
        uploadList.forEach(item => {
          if (item.url.indexOf(file.name) !== -1) {
            isExit = true
          }
        })
      }
      if (isExit) {
        this.errMsgAction(file.name, '【文件已经存在】')
        return { errcode: false, selfShow: true }
      }
      return { errcode: true }
    },
    insert () {
      if (this.formLeft.meeting_time === '' || this.formLeft.meeting_time === undefined) {
        this.$Message.error('会议日期不能为空！！！！！！！！！！')
      } else {
        if (this.formLeft.id === undefined) {
          let time = new Date(this.formLeft.meeting_time)
          this.formLeft.meeting_time = time.getFullYear() + '-' + (time.getMonth() + 1) + '-' + time.getDate()
          this.formLeft.select_type = this.select_type
          insertZlUnity(this.formLeft).then(ret => {
            if (ret.data.errcode === 0) {
              this.$Message.success('成功')
              this.$router.push({
                path: 'IdeologicalCognitions'
              })
            } else if (ret.data.errcode === 9999) {
              this.$Message.error('不能重复添加')
            }
          })
        } else {
          this.formLeft.select_type = this.select_type
          updateUnity(this.formLeft).then(ret => {
            if (ret.data.errcode === 0) {
              this.$Message.success('修改成功')
              this.$router.push({
                path: 'IdeologicalCognitions'
              })
            } else {
              this.$Message.error('修改失败')
            }
          })
        }
      }
      // console.log(this.formLeft.id, 'id')
      // if (this.formLeft.id === undefined) {
      //   if (this.formLeft.meeting_time === '' || this.formLeft.meeting_time === undefined) {
      //     // console.log(111)
      //     this.formLeft.meeting_time = new Date()
      //   } else {
      //     // console.log(222)
      //     let time = new Date(this.formLeft.meeting_time)
      //     this.formLeft.meeting_time = time.getFullYear() + '-' + (time.getMonth() + 1) + '-' + time.getDate()
      //   }
      //   this.formLeft.select_type = this.select_type
      //   insertZlUnity(this.formLeft).then(ret => {
      //     if (ret.data.errcode === 0) {
      //       this.$Message.success('成功')
      //       this.$router.push({
      //         path: 'IdeologicalCognitions'
      //       })
      //     } else if (ret.data.errcode === 9999) {
      //       this.$Message.error('不能重复添加')
      //     }
      //   })
      // } else {
      //   this.formLeft.select_type = this.select_type
      //   updateUnity(this.formLeft).then(ret => {
      //     if (ret.data.errcode === 0) {
      //       this.$Message.success('修改成功')
      //       this.$router.push({
      //         path: 'IdeologicalCognitions'
      //       })
      //     } else {
      //       this.$Message.error('修改失败')
      //     }
      //   })
      // }
    },

    ok () {
      // let wc = { select_type: this.select_type }
      // sxwc(wc).then(ret => {
      //   console.log(wc, 'wc!')
      // })
      if (this.formLeft.meeting_time === '' || this.formLeft.meeting_time === undefined) {
        this.$Message.error('会议日期不能为空！！！！！！！！！！')
      } else {
        if (this.formLeft.id === undefined) {
          let time = new Date(this.formLeft.meeting_time)
          this.formLeft.meeting_time = time.getFullYear() + '-' + (time.getMonth() + 1) + '-' + time.getDate()
          this.formLeft.select_type = '1'
          insertZlUnity(this.formLeft).then(ret => {
            if (ret.data.errcode === 0) {
              this.$Message.success('成功')
              this.$router.push({
                path: 'IdeologicalCognitions'
              })
            } else if (ret.data.errcode === 9999) {
              this.$Message.error('不能重复添加')
            }
          })
        } else {
          this.formLeft.select_type = '1'
          updateUnity(this.formLeft).then(ret => {
            if (ret.data.errcode === 0) {
              this.$Message.success('成功')
              this.$router.push({
                path: 'IdeologicalCognitions'
              })
            } else {
              this.$Message.error('失败')
            }
          })
        }
        let state = { state: 'a', 'step': '统一思想' }
        insertZlStateUnity(state).then(ret => {
          if (ret.data.errcode === 0) {
            getCountStateList({ 'step': '统一思想' }).then(ret => {
              let a = ret.data.data
              console.log(a, 'a')
              if (a[0].state === 'a') {
                this.nn = true
              }
              console.log('bz', a[0])
            })
          }
        })
        this.$router.push({
          name: 'problemVulnerabilitys'
        })
      }
    }
  },
  mounted () {
    if (this.$route.query.a !== undefined) {
      this.formLeft = this.$route.query.a
      this.form.bmA = this.$route.query.a.department_name
      this.companyCode = this.$route.query.a.company_code
    } else {
      this.form.bmA = this.$store.state.user.severUserInfo.data.company_name
      console.log(this.tm)
    }
    getCountStateList({ 'step': '统一思想', companyCode: this.companyCode }).then(ret => {
      if (ret.data.data.length === 0) {
        return
      }
      console.log(ret, 'ret')
      if (ret.data.data[0].state === 'a') {
        this.nn = true
      }
    })
    this.init()
  }

}
</script>

<style scoped>
</style>
